#include "BridgeCenterEntity.h"
#include "EffectManager.h"



BridgeCenterEntity::BridgeCenterEntity(int id, int type, double x, double y)
{
	_data = new BridgeData(id, type, x + 1, y);
	_data->sprites->setState(_STATE_MAP_STAGE1_BRIDGE_CENTER_1);
	_data->sprites->currentSprite->setStartEnd(0,2);
	state = BridgeState::STATE_Assign;
	_counter = 0;
}

void BridgeCenterEntity::update(long time)
{
	if(state == BridgeState::STATE_End)
	{
		return;
	}
	if(EffectManager::currentBridgeIndex == _data->id && state == BridgeState::STATE_Assign)
	{
		state = BridgeState::STATE_Fire;
		_data->sprites->currentSprite->setStartEnd(2,3);
		this->getAbstractData()->canInteract = false;
		EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Bridge_Fier, this->_data->getRect()->X + (160/2 - this->_data->getRect()->Width) - 5, this->_data->getRect()->Y + 3);
	}
	else if(state == BridgeState::STATE_Fire)
	{
		_counter++;
		if(_counter == TIME_DELAY)
		{
			state = BridgeState::STATE_End;
			EffectManager::currentBridgeIndex++;
		}
	}
	else
	{
		_data->sprites->updateCurrent();
	}
}

void BridgeCenterEntity::draw(long time)
{
	if(state == BridgeState::STATE_End)
	{
		return;
	}
	else
	{
		_data->sprites->draw();
	}
}

AbstractData* BridgeCenterEntity::getAbstractData()
{
	return _data;
}
